//
//  HHNonePage.m
//  caishuitong
//
//  Created by qiysoft on 2017/5/13.
//  Copyright © 2017年 zhangxy. All rights reserved.
//

#import "HHNonePage.h"
#import "NSString+Size.h"

#define messageFont [UIFont systemFontOfSize:14]

@interface HHNonePage ()

@property (nonatomic, strong) UIImageView *noneImageV;

@end

@implementation HHNonePage

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
//        self.backgroundColor = BG_COLOR;
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.noneImageV];
    }
    
    return self;
}

- (UIImageView *)noneImageV {
    
    _noneImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, (WSCREENH_HEIGHT-64)/2-154/2, 270, 154)];
    _noneImageV.image = [UIImage imageNamed:@"wushuju_2"];
    _noneImageV.center = CGPointMake(self.center.x, _noneImageV.center.y);
    
    return _noneImageV;
}

#pragma mark - 类方法

+ (void)showOnView:(UIView *)view message:(NSString *)message {
    HHNonePage *page = [[HHNonePage alloc] initWithFrame:CGRectMake(0, 0, view.bounds.size.width, view.bounds.size.height)];
    page.message = message;
    [view addSubview:page];
    [view bringSubviewToFront:page]; // 确保把子视图放到最前面
}

+ (void)showOnView:(UIView *)view message:(NSString *)message once:(BOOL)once {
    if (once) {
        __block BOOL viewDidShow = NO;
        [view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj isKindOfClass:[HHNonePage class]]) {
                viewDidShow = YES;
                [view bringSubviewToFront:obj];
                *stop = YES;
            }
        }];
        if (viewDidShow) {
            return;
        }
    }
    
    HHNonePage *page = [[HHNonePage alloc] initWithFrame:CGRectMake(0, 0, view.bounds.size.width, view.bounds.size.height)];
    page.message = message;
    [view addSubview:page];
    [view bringSubviewToFront:page]; // 确保把子视图放到最前面
}

+ (void)removeSelfFromView:(UIView *)view {
    [view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj isKindOfClass:[HHNonePage class]]) {
            [obj removeFromSuperview];
            obj = nil;
        }
    }];
}

@end
